// 更新or不更新大纲
import { mainPointGenerate } from '@/services/ant-design-pro/highClassWrite';
import { nanoid } from 'nanoid';
import React from 'react';
const UpdateMain: React.FC<any> = ({
  scrollToBottom,
  setAILogs,
  triggerReference,
  writing_session_id,
  triggerArticleMain,
}) => {
  //更新大纲
  const handleUpdateMain = async () => {
    let systemTxtRecover2 = {
      key: nanoid(),
      type: 'systemTxtRecover',
      spend: 30,
      data: [`小麦正在更新大纲…`],
    };
    setAILogs((prev: any) => [...prev, systemTxtRecover2]);
    scrollToBottom();
    //手动 调用接口 更新大纲
    let res2 = await mainPointGenerate({ write_session_id: writing_session_id });
    if (res2.code === 0) {
      triggerReference(1); //更新参考内容
      triggerArticleMain(); //更新文章大纲
    }
  };
  //不更新大纲
  const handleNoUpdateMain = () => {
    let systemTxtRecover = {
      key: nanoid(),
      type: 'systemTxtRecover',
      data: [`不更新大纲`],
    };
    setAILogs((prev: any) => [...prev, systemTxtRecover]);
  };

  return (
    <div className="contentRichBox">
      <div className="contentRichTip">参考文件有可能会更改大纲，您可以选择：</div>
      <div className="contentRichList">
        <span className="contentRich-hd">根据参考文件，更新大纲</span>
        <span
          className="contentRich-bd"
          onClick={() => {
            handleUpdateMain();
          }}
        >
          更新大纲
        </span>
      </div>
      <div className="contentRichList">
        <span className="contentRich-hd">文件仅加入文章内容，不更改大纲</span>
        <span className="contentRich-bd" onClick={() => handleNoUpdateMain()}>
          不更新大纲
        </span>
      </div>
    </div>
  );
};

export default UpdateMain;
